package com.crane.oss.sports;

import com.crane.common.framework.http.apache.HttpClientUtils;
import com.crane.common.framework.http.apache.HttpResult;
import com.crane.oss.xunfei.req.QueryIndexCourseStatisticRangeReq;
import com.crane.oss.xunfei.req.QueryIndexCourseStatisticReq;
import com.crane.oss.xunfei.req.XunFeiApiRequest;
import com.crane.oss.xunfei.resp.*;
import com.fasterxml.jackson.core.type.TypeReference;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author zx
 */
@Component
public class XunFeiIndexApiService extends  XunFeiApiService{
    /**
     * 首页-课堂健康数据
     * @param request
     * @param uid
     * @return
     */
    public ApiListResponse<IndexHeartRecentResp> getIndexHeartRecent(XunFeiApiRequest request, String sid, String did, String uid) {
    	Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult=HttpClientUtils.get(xunFeiAppConfig.getUrl()+"/index/heart/recent",params);
        if(httpResult.isSuccess()){
            ApiListResponse<IndexHeartRecentResp> response=httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<IndexHeartRecentResp>>(){});
            return response;
        }
        return ApiListResponse.buildFailure();
    }

    /**
     * 首页-体育课基础数据
     * @param request
     * @param uid
     * @return
     */
    public ApiSingleResponse<IndexCourseStatisticResp> getIndexCourseStatistic(QueryIndexCourseStatisticReq request, String sid, String did, String uid) {
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult=HttpClientUtils.get(xunFeiAppConfig.getUrl()+"/index/course/statistic/"+request.getTime(),params);
        if(httpResult.isSuccess()){
            ApiSingleResponse<IndexCourseStatisticResp> response=httpResult.getDataObjectByJson(new TypeReference<ApiSingleResponse<IndexCourseStatisticResp>>(){});
            return response;
        }
        return ApiSingleResponse.buildFailure();
    }


    /**
     * 首页-体育课基础报表
     * @param request
     * @param uid
     * @return
     */
    public ApiSingleResponse<IndexCourseStatisticRangeResp> getIndexCourseStatisticRange(QueryIndexCourseStatisticRangeReq request, String sid, String did, String uid) {
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult=HttpClientUtils.get(xunFeiAppConfig.getUrl()+"/index/course/statistic/range/day",params);
        if(httpResult.isSuccess()){
            ApiSingleResponse<IndexCourseStatisticRangeResp> response=httpResult.getDataObjectByJson(new TypeReference<ApiSingleResponse<IndexCourseStatisticRangeResp>>(){});
            return response;
        }
        return ApiSingleResponse.buildFailure();
    }



    public static void main(String[] args) {
        XunFeiIndexApiService xunFeiApiService=new XunFeiIndexApiService();

//        QueryIndexCourseStatisticReq queryIndexCourseStatisticReq=new QueryIndexCourseStatisticReq();
//        queryIndexCourseStatisticReq.setTime("cycle");
//        System.out.println(xunFeiApiService.getIndexCourseStatistic(queryIndexCourseStatisticReq,"87", null,"3"));
//

        QueryIndexCourseStatisticRangeReq req =new QueryIndexCourseStatisticRangeReq();
//        req.setSectionId("xd1");
//        req.setNj("1");
        req.setClassIds("13");
        System.out.println(xunFeiApiService.getIndexCourseStatisticRange(req,"87", null,"3"));
    }

}

